package br.ufrj.neg.model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collection;

import br.ufrj.neg.bean.PapelBean;
import br.ufrj.neg.bean.TraducaoBean;

public class PapelModel {
	public Collection<PapelBean> listaPapel(PapelBean papelBean) {
		ResultSet rs = null;
		PreparedStatement ps=null;;
		Connection conn = ServiceLocator.getConnection();
		try {
			Collection<PapelBean> col = new ArrayList<PapelBean>();
			String sql = "Select * from papel";
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			PapelBean pb;
			while(rs.next()){
				pb = papelBean.getNewInstance();
				pb.setId(rs.getInt("PAPE_CD_ID"));					
				TraducaoBean traducao = TraducaoModel.getTraducoesElemento(pb);			
				pb.setDicionario( traducao.getDicionario() );
				col.add(pb);					
			}
			return col;
		} catch (Exception e) {
			System.out.println(e);
			return null;
		}finally{
			try{rs.close();}catch(Exception e){System.out.println(e);}
			try{ps.close();}catch(Exception e){System.out.println(e);}
			try{conn.close();}catch(Exception e){System.out.println(e);}
		}
	}
}
